var tempZid;
var zid;
function checkForEnter(event) {
	if (event.keyCode == 13) {
		encodeKeyword3();
		return false;
	}
}
function encodeKeyword(ky){
 if ( "" != ky )
	 $(":input[name='searchKeyword']").val(ky);
 var params = jQuery("#searchForm").serialize(); // http request parameters.
 params = encodeURI(params); 
 location.href="/ecmall/search/search.do?" + params;
}

function encodeKeyword2(){
	var params = jQuery("#formObj").serialize(); // http request parameters.
	params = encodeURI(params); 
	location.href="/ecmall/search/search.do?" + params;
}

function encodeKeyword3(){
	var params = jQuery("#searchForm").serialize(); // http request parameters.
	params = encodeURI(params); 
	location.href="/ecmall/search/search.do?" + params;
}

$().ready(function(){
	//hot-search
	if ($.browser.mozilla) 
		$(":input[name='searchKeyword']").keypress(checkForEnter);
	else
		$(":input[name='searchKeyword']").keydown(checkForEnter);

	$("#menu > ul > li:div").each(function(index,item){
		$(this).hover(function(){
			traceGWD(101+index);
		});
		var timeId;
		$(this).bind("mouseenter", function(){
			var obj=$(this);
			timeId=setTimeout(function(){
				obj.children("div.sub-menu").show();
			},500);
		}).bind("mouseleave", function(){
			clearTimeout(timeId);
			$(this).children("div.sub-menu").hide();
		});
	});
	//sidebar-category
	$("div.ca-index-menu > ul.sdbar-sub > li:has(ul)").each(function(index,item){
		$(this).hover(function(event){
			$("ul.moreshow").each(function(){
				$(this).hide();
			});
			// 停止元素动画
			$(this).children('ul.moreshow').show();
		},function(){
			$(this).children('ul.moreshow').hide();
	    });
	});
	
	//index maingold
	$("div.sel-box > a").each(function(index,item){
		$(this).hover(function(event){
			$("div.sel-box > a").each(function(index2,item){
				$(this).attr("class","sel-num" + (index2+1));
			});
			$("div[id*='main-gold-']").each(function(){
				$(this).hide();
			});
			$(this).attr("class",$(this).attr("class")+"f");
			$("#main-gold-" + (index+1)).show();
		});
	});
	
	//category maingold
	$("div.tab-area.main-gold > ul.tab-list > li").each(function(index,item){
		$(this).hover(function(event){
			$("li",$(item).parent()).each(function(){
				if ( $(this).attr("class").split("-").length == 3 )
					$(this).attr("class",$(this).attr("class").substring(0,$(this).attr("class").length-2));
			});
			$("div[id*='main-gold-']").each(function(){
				$(this).hide();
			});
			$(this).attr("class",$(this).attr("class")+"-f");
			$("#main-gold-" + (index+1)).show();
		});
	});

	//sale top mid btm
	$("div.filterbar").each(function(index,item){
		var tempClass = $(this).parent().attr("class").split(" ")[1];
		$("div.mid-box." + tempClass + " > div.filterbar > a").each(function(index2){
			$(this).hover(function(event){
				$("div.mid-box." + tempClass + " > div.filterbar > a").each(function(){
					$(this).removeClass();
				});
				$("ul[id*='" + tempClass.split("-")[1] + "-sale-bar-']").each(function(){
					$(this).hide();
				});
				$(this).addClass("nowfcous");
				var productImageBlock = $("#" + tempClass.split("-")[1] + "-sale-bar-" + (index2+1));
				productImageBlock.show();
				var productImages = productImageBlock.find("img");
				productImages.each(function(){
					if ($(this).attr('src') != $(this).attr('original')) {
						$(this).attr('src', $(this).attr('original'));
					}
				});
				return false;
			});
			
		});
	});
	
	//promotion top mid btm
	$("div.tab-area[id*='-tab-area']").each(function(index,item){
		var tempId = this.id;
		$("ul.tab-list > li",$(this)).each(function(index2){
			$(this).hover(function(event){
				$("ul.tab-list > li",$(item)).each(function(){
					if ( $(this).attr("class").split("-").length == 3 )
						$(this).attr("class",$(this).attr("class").substring(0,$(this).attr("class").length-2));
				});
				$("div[id*='" + tempId +"-']").each(function(){
					$("#" + this.id).hide();
				});
				$(this).attr("class",$(this).attr("class")+"-f");
				$("#" + tempId +"-" + (index2+1)).show();
			});
		});
	});
	//idx right tab3
	$("div#tab3_idx > ul.tab-right > li").each(function(index,item){
		$(this).hover(function(){
			$("div#tab3_idx > ul.tab-right > li").each(function(index2){
				var tabSeq = index2 + 1;
				$(this).attr("class","tab-" + tabSeq);
			});
			$("div#tab3_idx > div").each(function(){
				$(this).hide();
			});
			$(this).attr("class",$(this).attr("class") + "f");
//			$("div#tab3_idx > div").eq(index).show();
			var productImageBlock = $("div#tab3_idx > div").eq(index);
			productImageBlock.show();
			var productImages = productImageBlock.find("img");
			productImages.each(function(){
				if ($(this).attr('src') != $(this).attr('original')) {
					$(this).attr('src', $(this).attr('original'));
				}
			});
		});
	});
	
	//category right tab3
	$("div#tab3 > ul.tab-right > li").each(function(index,item){
		$(this).hover(function(){
			$("div#tab3 > ul.tab-right > li").each(function(index2){
				$(this).attr("class","tab-" + (index2+1));
			});
			$("div#tab3 > div").each(function(){
				$(this).hide();
			});
			$(this).attr("class","tab-" + (index+1) + "f");
			var productImageBlock = $("div#tab3 > div").eq(index);
			productImageBlock.show();
			var productImages = productImageBlock.find("img");
			productImages.each(function(){
				if ($(this).attr('src') != $(this).attr('original')) {
					$(this).attr('src', $(this).attr('original'));
				}
			});
		});
	});	
	
	//hotsel
	var hotsel_cur = 1;
    $("#hotsel_left").click(function(){
      if(hotsel_cur>1){
        hotsel_cur--;
        $(":div[id*=hotsel_box_]").hide();
        var hotSelectBox = $("#hotsel_box_"+hotsel_cur);
        hotSelectBox.show();
		var hotSelectImages = hotSelectBox.find("img");
		hotSelectImages.each(function(){
			if ($(this).attr('src') != $(this).attr('original')) {
				$(this).attr('src', $(this).attr('original'));
			}
		});
      }else{
    	  $("#hotsel_box_1").hide(); 
    	  var hotselSize = $(":div[id*=hotsel_box_]").size();
    	  var hotSelectBox = $("#hotsel_box_"+hotselSize);
          hotSelectBox.show();
          var hotSelectImages = hotSelectBox.find("img");
          hotSelectImages.each(function(){
        	  if ($(this).attr('src') != $(this).attr('original')) {
        		  $(this).attr('src', $(this).attr('original'));
        	  }
          });
    	  hotsel_cur = hotselSize;
      }
    });
    $("#hotsel_right").click(function(){
      if(hotsel_cur<$(":div[id*=hotsel_box_]").size()){
        hotsel_cur++;
        $(":div[id*=hotsel_box_]").hide();
        var hotSelectBox = $("#hotsel_box_"+hotsel_cur);
        hotSelectBox.show();
  		var hotSelectImages = hotSelectBox.find("img");
  		hotSelectImages.each(function(){
  			if ($(this).attr('src') != $(this).attr('original')) {
  				$(this).attr('src', $(this).attr('original'));
  			}
  		});
      }else{
    	  var hotselSize = $(":div[id*=hotsel_box_]").size();
    	  $("#hotsel_box_" + hotselSize).hide(); 
    	  var hotSelectBox = $("#hotsel_box_1");  
          hotSelectBox.show();
          var hotSelectImages = hotSelectBox.find("img");
          hotSelectImages.each(function(){
        	  if ($(this).attr('src') != $(this).attr('original')) {
        		  $(this).attr('src', $(this).attr('original'));
        	  }
          });
    	  hotsel_cur = 1;
      }
    });
	
    //goldfour
    $("div.gold-four > ul.tab-right > li").each(function(index,item){
		$(this).hover(function(){
			$("div.gold-four > ul.tab-right > li").each(function(index2){
				var tabSeq = index2 + 1;
				$(this).attr("class","tab-" + tabSeq);
			});
			$("div.gold-four > div.gold-four-show").each(function(){
				$(this).hide();
			});
			$(this).attr("class",$(this).attr("class")+"f");
			var productImageBlock = $("div.gold-four > div.gold-four-show").eq(index);
			productImageBlock.show();
			var productImages = productImageBlock.find("img");
			productImages.each(function(){
				if ($(this).attr('src') != $(this).attr('original')) {
					$(this).attr('src', $(this).attr('original'));
				}
			});
		});
	});
    
    //goldbn
    $("div.gold-bn > ul > li").each(function(index,item){
		$(this).hover(function(){
			$("div.gold-bn > ul > li").each(function(index2){
				$(this).attr("class","gdbn-" + (index2+1));
			});
			$("div.gold-bn > div").each(function(){
				$(this).hide();
			});
			$(this).attr("class","gdbn-" + (index+1) + "f");
			$("div.gold-bn > div").eq(index).show();
		});
	});        
});

//sidebar-index
function sidrbarIndex(){
	$("div.sidebar > ul > li").each(function(index,item){
		$(this).hover(function(){
			$("div.sidebar > ul > li").each(function(index2){
				$(this).attr("class","tab" + (index2+1));
			});
			$("div.sidebar > div").each(function(){
				$(this).hide();
			});
			$(this).attr("class","tab" + (index+1) + "-f");
			$("div.sidebar > div").eq(index).show();
		});
	});
}

function checkLogin(){
	var slid = '';
	var login = '';
	var lmt = '';
	 cookies=document.cookie.split(';');
	   for(i=0;i<cookies.length;i++){
		  theCookie=cookies[i].split('=');
		  if(theCookie[0].replace(' ', '')=='_1.100.SN'){
			 if(theCookie[1]!=''){
				 slid = Base64.decode(theCookie[1]);
			 }
		  }
		  if(theCookie[0].replace(' ', '')=='_1.100.N'){
			 if(theCookie[1]!=''){
				 login = theCookie[1];
			 }
		  }
		  if(theCookie[0].replace(' ', '')=='_1.100.LD'){
			  //check domain
			  if(window.location.hostname!=theCookie[1]){
				  $.post("/ecmall/jsonlogout.do",{},null,"json");
				  return '';
			  }
		  }
		  if(theCookie[0].replace(' ', '')=='LMT'){
			  lmt = theCookie[1];
		  }
	   }
	 var now = new Date().getTime();
	 if(login == ''){
		 document.cookie = 'LMT='+now;
		 return '';
	 }else{
		// if((parseInt(now)-parseInt(lmt))/60000>30){
		//	 $.post("/ecmall/jsonlogout.do",{},
		//			 function callback(result){
		//				window.location.reload(); 
		//	 		 }
		//	 ,"json");
			 
		// }else{
			 document.cookie = 'LMT='+now;
		// }
	 }
	 return slid;
}

function traceGWD(num){
	if (window.GridsumWebDissector) {
		window.GridsumSnapshotID=num;
	}
}